/*
 *  Acronym                : I2c.h
 *  Name of Module         : TrmI2c.a
 *  Product/Project        : Rhapsody for TriMedia
 *  12NC                   :
 *  Group number           : 885540
 *  Creation date          : 1999-03-17
 *  Modification date      : 2001-07-31
 *  Related documents      : CTB554-98-B155
 *  Program language       : C
 *  Documentation language : English
 *  Status                 : Preliminary
 *  Author(s)              : P.J. Zander
 *
 *                Copyright (C) Philips Electronics N.V. 1999-2001
 *                   CFT Centre for Industrial Technology
 *                             Industrial Vision
 *                        Eindhoven - The Netherlands
 *
 *       All rights are reserved. Reproduction in whole or in part is
 *           prohibited without the written consent of the author.
 */

/*
 *  Description:
 *    Local header file of Subsystem: I2c
 *
 */

#ifndef _I2C_H
#define _I2C_H

/*
 *----------------------------------------------------------------------------
 * C++ Define
 *----------------------------------------------------------------------------
 */

#ifdef __cplusplus
extern "C" {
#endif

/*
 *----------------------------------------------------------------------------
 * Subsystem Defines
 *----------------------------------------------------------------------------
 */

#define I2C_READ             (0)
#define I2C_WRITE            (1)

#define I2C_MAX_ADDRESS      (0xFF)
#define I2C_MAX_BYTES        (4)
#define I2C_MAX_BLOCK        (255)
#define I2C_MAX_PRIORITY     (7)

/*
 *----------------------------------------------------------------------------
 * Subsystem Variables
 *----------------------------------------------------------------------------
 */

extern int i2cDebug;

extern struct trm_i2c
{
    int           status;
    unsigned long semId;
    
    unsigned long semTimeout;
    unsigned long ackEvent;
    unsigned long ackTimeout;
    
    struct
    {
        int            status;
        int            rwMode;
        int            nBytes;
        unsigned char *pData;

        unsigned long  taskId;
        unsigned long  ackEvent;
  } isr;
} trmI2c;

/*
 *----------------------------------------------------------------------------
 * Subsystem Macros
 *----------------------------------------------------------------------------
 */

#define I2C_DATA_REGISTER_WRITE(dataReg,pData,n)    \
{                                                   \
    int i;                                          \
    (dataReg)=0;                                    \
    for (i=0;i<(n);i++)                             \
    {                                               \
        (dataReg)|=((pData)[i])<<((3-i)*8);         \
    }                                               \
}

#define I2C_DATA_REGISTER_READ(dataReg,pData,n)     \
{                                                   \
    int i;                                          \
    *(unsigned int*)(pData)=0;                      \
    for (i=0;i<(n);i++)                             \
    {                                               \
        (pData)[i]=((dataReg)>>((3-i)*8))&0xFF;     \
    }                                               \
}

/*
 *----------------------------------------------------------------------------
 * Subsystem Function Prototypes
 *----------------------------------------------------------------------------
 */

    void TrmI2cIsr(
        void);
    
    int TrmI2cReadWrite(
       unsigned int  rwMode,
       unsigned int  address,
       unsigned int  nBytes,
       unsigned char pData[]);

/*
 *----------------------------------------------------------------------------
 */

#ifdef __cplusplus
}
#endif

#endif 
